package org.dakuo.sgfyModel;


public class SgfyResourceGroup {
	SgfyResource[] resList = { new SgfyResource(SgfyResource.RESOURCE_LUMBER),
			new SgfyResource(SgfyResource.RESOURCE_CLAY),
			new SgfyResource(SgfyResource.RESOURCE_IRON),
			new SgfyResource(SgfyResource.RESOURCE_CROP),
			new SgfyResource(SgfyResource.RESOURCE_POPULATION) };

	public SgfyResourceGroup() {
	}
	
	public void addResource(SgfyResource res){
		for(int i=0;i<5;i++)
			if(resList[i].equals(res))
				resList[i]=res;
	}
	
	float[] getNow() {
		float[] res = { 0, 0, 0, 0, 0 };
		for (int i = 0; i < 5; i++)
			res[i] = this.resList[i].getNow();
		return res;
	}

	float[] getMax() {
		float[] res = { 0, 0, 0, 0, 0 };
		for (int i = 0; i < 5; i++)
			res[i] = this.resList[i].getMax();
		return res;
	}

	float[] getSpeed() {
		float[] res = { 0, 0, 0, 0, 0 };
		for (int i = 0; i < 5; i++)
			res[i] = this.resList[i].getSpeed();
		return res;
	}

	float[] getIncrease() {
		float[] res = { 0, 0, 0, 0, 0 };
		for (int i = 0; i < 5; i++)
			res[i] = this.resList[i].getIncrease();
		return res;
	}

	float[] getBuff() {
		float[] res = { 0, 0, 0, 0, 0 };
		for (int i = 0; i < 5; i++)
			res[i] = this.resList[i].getBuff();
		return res;
	}

	void setNow(float l, float cl, float ir, float cr, float po) {
		resList[0].setNow(l);
		resList[1].setNow(cl);
		resList[2].setNow(ir);
		resList[3].setNow(cr);
		resList[4].setNow(po);
	}

	void setMax(float l, float cl, float ir, float cr, float po) {
		resList[0].setMax(l);
		resList[1].setMax(cl);
		resList[2].setMax(ir);
		resList[3].setMax(cr);
		resList[4].setMax(po);
	}

	void setSpeed(float l, float cl, float ir, float cr, float po) {
		resList[0].setSpeed(l);
		resList[1].setSpeed(cl);
		resList[2].setSpeed(ir);
		resList[3].setSpeed(cr);
		resList[4].setSpeed(po);
	}

	void setIncrease(float l, float cl, float ir, float cr, float po) {
		resList[0].setIncrease(l);
		resList[1].setIncrease(cl);
		resList[2].setIncrease(ir);
		resList[3].setIncrease(cr);
		resList[4].setIncrease(po);
	}

	void setBuff(float l, float cl, float ir, float cr, float po) {
		resList[0].setBuff(l);
		resList[1].setBuff(cl);
		resList[2].setBuff(ir);
		resList[3].setBuff(cr);
		resList[4].setBuff(po);
	}

	public void consumeResource(float l, float cl, float ir, float cr, float po) {
		resList[0].setNow(resList[0].getNow() - l);
		resList[1].setNow(resList[1].getNow() - cl);
		resList[2].setNow(resList[2].getNow() - ir);
		resList[3].setNow(resList[3].getNow() - cr);
		resList[4].setNow(resList[4].getNow() - po);
	}

	public void consumeResource(float[] resNeed) {
		for (int i = 0; i < 5; i++)
			resList[i].setNow(resList[i].getNow() - resNeed[i]);
	}

	public void attributeToResource(float l, float cl, float ir, float cr,
			float po) {
		resList[0].setSpeed(resList[0].getSpeed() + l);
		resList[1].setSpeed(resList[1].getSpeed() + cl);
		resList[2].setSpeed(resList[2].getSpeed() + ir);
		resList[3].setSpeed(resList[3].getSpeed() + cr);
		resList[4].setSpeed(resList[4].getSpeed() + po);
	}

	public void attributeToResource(float[] resNeed) {
		for (int i = 0; i < 5; i++)
			resList[i].setSpeed(resList[i].getSpeed() + resNeed[i]);
	}

	public String toString() {
		String s = "";
		for (int i = 0; i < 5; i++)
			s += this.resList[i];
		return s;
	}

}
